
# -*- encoding=utf-8 -*-
# 1、使用4号触发器（一个红外反射传感器）和13号电机（饮水机）
# 2、触发红外对射1打开电机，未触发关闭电机

from froModuleDrivers.generalDeviceDriver import GeneralDeviceDriver
from froModuleDrivers.nioManager import NioManager
import time
from froModuleDrivers import LOGGER


# LOGGER.set_lvl("debug")

driver = GeneralDeviceDriver("192.168.50.196", 4001)
manager = NioManager(driver)
manager.run()

driver.showVersion()
driver.setWaitTime(0.4) # 设置指令返回的等待时间为0.4秒
while True:
    trigger = driver.getTriggerStatus(4) # 获取触发器状态
    # print(trigger)
    if trigger[0] == 0:
        print(f"已触发，打开饮水机")
        driver.setMotorClockwise(13, 50) # 控制电机
    else:
        print(f"未触发")
        driver.setMotorStop(13) # 停止电机

manager.shutdownGracefully() # 等待指令执行完毕后系统退出